import { merge } from 'lodash';
import Cookies from 'js-cookie';

const cookies = {};

/**
 * @description 存储 cookie 值
 * @param {String} name cookie name
 * @param {String} value cookie value
 * @param {Object} setting cookie setting
 */
cookies.set = (name = 'default', value = '', cookieSetting = {}) => {
  const currentCookieSetting = {
    expires: 1
  };
  merge(currentCookieSetting, cookieSetting);
  Cookies.set(name, value, currentCookieSetting);
};

/**
 * @description 拿到 cookie 值
 * @param {String} name cookie name
 */
cookies.get = (name = 'default') => {
  return Cookies.get(name);
};

/**
 * @description 拿到 cookie 全部的值
 */
cookies.getAll = () => {
  return Cookies.get();
};

/**
 * @description 删除 cookie
 * @param {String} name cookie name
 */
cookies.remove = (name = 'default') => {
  return Cookies.remove(name);
};

export default cookies;
